package com.endpoint.member.controller;


import com.endpoint.common.utils.JwtTokenUtil;
import com.endpoint.common.utils.ResultBean;
import com.endpoint.member.service.MemberReadHistoryService;
import com.endpoint.member.vo.MemberBookshelfVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 用户阅读记录表 前端控制器
 * </p>
 *
 * @author Jack_Li
 * @since 2024-07-03
 */
@RestController
@RequestMapping("/member/memberReadHistory")
public class MemberReadHistoryController {

    @Autowired
    private MemberReadHistoryService memberReadHistoryService;

    @PostMapping("/addReadHistory")
    public ResultBean addReadHistory(@RequestBody MemberBookshelfVo vo
            , @RequestHeader(name="Authorization",required = false)String  token ){
        Long userId = JwtTokenUtil.getUserIdFromToken(token);
        if(userId!=null){//如果token未过期 登录过 执行添加阅读记录
            vo.setMemberId(userId);
            ResultBean res = memberReadHistoryService.addReadHistory(vo);
            return  res;
        }
        return ResultBean.ok("免费未登录用户不加记录");
    }

}

